package com.ruoyi.web.controller.stock;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockTopBoard;
import com.ruoyi.stock.service.IStockTopBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 今日涨停个股Controller
 *
 * @author ruoyi
 * @date 2025-07-12
 */
@RestController
@RequestMapping("/stock/board")
public class StockTopBoardController extends BaseController {
    @Autowired
    private IStockTopBoardService stockTopBoardService;

    /**
     * 查询今日涨停个股列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockTopBoard stockTopBoard) {
        startPage();
        List<StockTopBoard> list = stockTopBoardService.selectStockTopBoardList(stockTopBoard);
        return getDataTable(list);
    }

    /**
     * 导出今日涨停个股列表
     */
    @Log(title = "今日涨停个股", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockTopBoard stockTopBoard) {
        List<StockTopBoard> list = stockTopBoardService.selectStockTopBoardList(stockTopBoard);
        ExcelUtil<StockTopBoard> util = new ExcelUtil<StockTopBoard>(StockTopBoard.class);
        util.exportExcel(response, list, "今日涨停个股数据");
    }


    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<StockTopBoard> util = new ExcelUtil<StockTopBoard>(StockTopBoard.class);
        List<StockTopBoard> list = util.importExcel(file.getInputStream());
        return stockTopBoardService.importData(list, updateSupport);
    }

    /**
     * 获取今日涨停个股详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(stockTopBoardService.selectStockTopBoardById(id));
    }

    /**
     * 新增今日涨停个股
     */
    @Log(title = "今日涨停个股", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockTopBoard stockTopBoard) {
        return toAjax(stockTopBoardService.insertStockTopBoard(stockTopBoard));
    }

    /**
     * 修改今日涨停个股
     */
    @Log(title = "今日涨停个股", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockTopBoard stockTopBoard) {
        return toAjax(stockTopBoardService.updateStockTopBoard(stockTopBoard));
    }

    /**
     * 删除今日涨停个股
     */
    @Log(title = "今日涨停个股", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockTopBoardService.deleteStockTopBoardByIds(ids));
    }
}
